package com.easepal802s.project.observer;

import com.clj.fastble.data.BleDevice;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by FHB on 2018/4/18.
 */
public class CloseObserver {

    private static CloseObserver mInst = null;
    private static Object mLock = new Object();

    private List<OnCloseListerner> mOnCloseListerner;

    private CloseObserver(){
        mOnCloseListerner = new ArrayList<OnCloseListerner>();
    }

    public static CloseObserver getInst(){
        if(mInst == null){
            synchronized(mLock){
                if(mInst == null){
                    mInst = new CloseObserver();
                }
            }
        }
        return mInst;
    }

    public void  registerObserver(OnCloseListerner action){
        if(!mOnCloseListerner.contains(action)){
            mOnCloseListerner.add(action);
        }
    }

    public void removeObserver(OnCloseListerner action){
        mOnCloseListerner.remove(action);
    }


    public void noticeonClose(){
        for (int i = 0; i < mOnCloseListerner.size(); i++) {
            try {
                mOnCloseListerner.get(i).onClose();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public interface OnCloseListerner {
        //连接状态
        void onClose();


    }


}
